import { computed, ComputedRef, reactive, ref, watchEffect } from 'vue'
import { defineStore } from 'pinia'
import { utils } from 'yklib';
const {
    cal_pillar_diameter,
    calRopeDiameter,
    calRopeMassPer100m,
    calShaftDiameter,
    getRopeClass,
    getRopeCoreClass,
    getRopeStrands
} = utils;

export const useSgesCStore = defineStore('sgesCalC', () => {

    const capChargeTotalSta = ref<number>(209.3945)
    const powerChargeTotalSta = ref<number>(52.609)
    const totalChargeTime = ref<number>(2)
    const cal_power = ref<boolean>(true)
    const vibrant_para = ref<number>(1);

    const vibrant_option = [
        {
            label: "有效提升高度",
            value: 1,
        }, {
            label: "重物块密度",
            value: 2
        }, {
            label: "重物块长",
            value: 3
        }, {
            label: "重物块宽",
            value: 4
        }, {
            label: "重物块高",
            value: 5
        }, {
            label: "系统效率",
            value: 6
        }
    ]

    watchEffect(() => {
        if (cal_power.value) {
            powerChargeTotalSta.value = computed(() => capChargeTotalSta.value / totalChargeTime.value).value
        } else {
            totalChargeTime.value = computed(() => capChargeTotalSta.value / powerChargeTotalSta.value).value
        }
    })

    const heightTower = ref(150)  // 1
    const density = ref(2400)  // 2
    const lengthBlock = ref(6) // 3
    const widthBlock = ref(3); // 4
    const heightBlock = ref(19); // 5
    const etaSystem = ref(0.85)
    const volumeBlock = ref(0)
    const massBlock = ref(0)
    const etaCharge = ref(1)
    const etaDischarge = ref(1)

    const numOfGens = ref(72)
    const numOfCellsPerSide = ref(4)  // 发电机每一侧的重物块数量
    const numOfCellsPerGen = computed(() => numOfCellsPerSide.value * 2)  // 每一个发电机驱动的重物数量
    const totalBlocksNum = computed(() => numOfGens.value * numOfCellsPerGen.value)

    const numGensPerGroup = ref(1)  // 构建3D模型时，每个塔组中的电机数量
    numGensPerGroup.value = computed(() => {
        let _ = Math.sqrt(totalBlocksNum.value)
        let rows = 1
        for (let i = Math.floor(_); totalBlocksNum.value; i++) {
            if (totalBlocksNum.value % i == 0) {
                rows = i
                break
            }
        }
        return rows
    }).value

    const totalMassBlocks = ref(0)
    const totalGravityEnergy = ref(0)
    const g = ref(9.8)
    watchEffect(() => {
        switch (vibrant_para.value) {
            case 1: // 计算有效提升高度
                volumeBlock.value = computed(() => heightBlock.value * widthBlock.value * lengthBlock.value).value
                massBlock.value = computed(() => volumeBlock.value * density.value).value  // kg
                totalMassBlocks.value = computed(() => massBlock.value * totalBlocksNum.value).value  // kg
                etaDischarge.value = computed(() => Math.sqrt(etaSystem.value)).value
                etaCharge.value = computed(() => Math.sqrt(etaSystem.value)).value
                totalGravityEnergy.value = computed(() => capChargeTotalSta.value * 3600000000 * etaCharge.value).value  // J
                heightTower.value = computed(() => totalGravityEnergy.value / totalMassBlocks.value / g.value).value
                break
            case 2:
                volumeBlock.value = computed(() => heightBlock.value * widthBlock.value * lengthBlock.value).value
                etaDischarge.value = computed(() => Math.sqrt(etaSystem.value)).value
                etaCharge.value = computed(() => Math.sqrt(etaSystem.value)).value
                totalGravityEnergy.value = computed(() => capChargeTotalSta.value * 3600000000 * etaCharge.value).value
                totalMassBlocks.value = computed(() => totalGravityEnergy.value / heightTower.value / g.value).value
                massBlock.value = computed(() => totalMassBlocks.value / totalBlocksNum.value).value
                density.value = computed(() => massBlock.value / volumeBlock.value).value
                break
            case 3:
                etaDischarge.value = computed(() => Math.sqrt(etaSystem.value)).value
                etaCharge.value = computed(() => Math.sqrt(etaSystem.value)).value
                totalGravityEnergy.value = computed(() => capChargeTotalSta.value * 3600000000 * etaCharge.value).value
                totalMassBlocks.value = computed(() => totalGravityEnergy.value / heightTower.value / g.value).value
                massBlock.value = computed(() => totalMassBlocks.value / totalBlocksNum.value).value
                volumeBlock.value = computed(() => massBlock.value / density.value).value
                lengthBlock.value = computed(() => volumeBlock.value / widthBlock.value / heightBlock.value).value
                break
            case 4:
                etaDischarge.value = computed(() => Math.sqrt(etaSystem.value)).value
                etaCharge.value = computed(() => Math.sqrt(etaSystem.value)).value
                totalGravityEnergy.value = computed(() => capChargeTotalSta.value * 3600000000 * etaCharge.value).value
                totalMassBlocks.value = computed(() => totalGravityEnergy.value / heightTower.value / g.value).value
                massBlock.value = computed(() => totalMassBlocks.value / totalBlocksNum.value).value
                volumeBlock.value = computed(() => massBlock.value / density.value).value
                widthBlock.value = computed(() => volumeBlock.value / lengthBlock.value / heightBlock.value).value
                break
            case 5:
                etaDischarge.value = computed(() => Math.sqrt(etaSystem.value)).value
                etaCharge.value = computed(() => Math.sqrt(etaSystem.value)).value
                totalGravityEnergy.value = computed(() => capChargeTotalSta.value * 3600000000 * etaCharge.value).value
                totalMassBlocks.value = computed(() => totalGravityEnergy.value / heightTower.value / g.value).value
                massBlock.value = computed(() => totalMassBlocks.value / totalBlocksNum.value).value
                volumeBlock.value = computed(() => massBlock.value / density.value).value
                heightBlock.value = computed(() => volumeBlock.value / lengthBlock.value / widthBlock.value).value
                break
            case 6: // eta
                volumeBlock.value = computed(() => heightBlock.value * widthBlock.value * lengthBlock.value).value
                massBlock.value = computed(() => volumeBlock.value * density.value).value
                totalMassBlocks.value = computed(() => massBlock.value * totalBlocksNum.value).value
                totalGravityEnergy.value = computed(() => totalMassBlocks.value * g.value * heightTower.value).value
                etaCharge.value = computed(() => totalGravityEnergy.value / capChargeTotalSta.value / 3600000000).value
                etaDischarge.value = computed(() => etaCharge.value).value
                etaSystem.value = computed(() => etaCharge.value * etaDischarge.value).value
                break
            default:
                volumeBlock.value = computed(() => heightBlock.value * widthBlock.value * lengthBlock.value).value
                massBlock.value = computed(() => volumeBlock.value * density.value).value
                break

        }
    })

    const totalGravityEnergy_MJ = computed(() => totalGravityEnergy.value / 1000000) // 重物的总重力势能
    const capDischargeTotalSta = computed(() => capChargeTotalSta.value * etaSystem.value)  // 电站总发电容量
    const weightBlock = computed(() => massBlock.value * g.value)  // 重物块的重力
    const etaCharge_100 = computed(() => etaCharge.value * 100)  // 系统充电效率，单位%
    const etaDischarge_100 = computed(() => etaDischarge.value * 100)  // 系统发电效率，单位%
    const etaSystem_100 = computed(() => etaSystem.value * 100)  // 系统效率，单位%

    const totalMassAssistance_t = ref(50000);  // 塔顶辅助设备总重量，发电机、轴系
    const totalMassAssistance = computed(() => totalMassAssistance_t.value * 1000);
    const totalWeightAssistance = computed(() => totalMassAssistance.value * g.value)

    const pillar_set = reactive({
        steelType: "Q235",
        steelDensity: 7.85,
        concreteType: "C70",
        concreteDensity: 2.5,
        steelRatio: 0.14,
        safetyFactor: 1.5,
    })

    const diameter_pillar = computed(() => {
        return cal_pillar_diameter(pillar_set, heightTower, weightBlock, g) / 1000
    })  // 承重柱直径,m

    const distancePillarWeight = ref(0.2)
    const widthGenRegion = ref(4) // 发电机列的宽度，不包含柱子的尺寸
    const areaControlRoom = ref(50)  // 集控室占地面积

    const widthPerGenGroup = computed(() => {  // 每个塔的宽度按一个柱子计算，总面积需要再加个柱子直径
        // 重物和间隙的总宽度
        return widthBlock.value + 2 * Number(distancePillarWeight.value) + diameter_pillar.value
    })

    const lengthPerGenGroup = computed(() => {
        let _1 = numOfCellsPerGen.value * (lengthBlock.value + 2 * Number(distancePillarWeight.value))
        let _2 = (numOfCellsPerGen.value + 2) * diameter_pillar.value// 长度方向柱子的总尺寸
        return _1 + _2 + Number(widthGenRegion.value)
    })

    const areaPerGenGroup = computed(() => widthPerGenGroup.value * lengthPerGenGroup.value)
    const areaTotalTower = computed(() => areaPerGenGroup.value * numOfGens.value)
    const areaCoe = ref(1) // 面积裕度系数

    const areaTotalSta = computed(() => {
        return (areaTotalTower.value + Number(areaControlRoom.value)) * Number(areaCoe.value)  // 由文本输入框获得的数值进来是文本类型的代理，需要转换成数字
    })

    const numGensSim = ref(36)

    // 单次运行发电机数量占比
    const powerSingleBlock_MW = computed(() => powerChargeTotalSta.value * etaCharge.value / numOfCellsPerGen.value / numGensSim.value)
    const powerSingleBlock = computed(() => powerSingleBlock_MW.value * 1000000) // 单个重物的运行功率
    const velWeight_m_s = computed(() => powerSingleBlock.value / weightBlock.value)

    // 同时运行的重物占比，如果同时运行1/4，且充电时间为4小时，则单程运行需要1小时，如果同时运行1/2，且充电时间为4小时，则单程运行需要2小时
    const timeSinglePass = computed(() => heightTower.value / velWeight_m_s.value / 3600)
    const proSim = computed(() => timeSinglePass.value / totalChargeTime.value)
    // const numGensSim = computed(() => proSim.value * numOfGens.value)

    const velWeight_m_h = computed(() => velWeight_m_s.value * 3600)

    // const powerSingleBlock = computed(() => velWeight_m_s.value * weightBlock.value) // 单个重物的运行功率
    // const powerSingleBlock_MW = computed(() => powerSingleBlock.value / 1000000)
    const speedRotateGen = ref(600)

    // 额定工况下同时运行的重物的功率
    const powerBlocksSim = computed(() => powerSingleBlock.value * numGensSim.value * numOfCellsPerGen.value)
    // 单个发电机的功率
    const chargePowerSingleGen = computed(() => powerSingleBlock.value * numOfCellsPerGen.value / etaCharge.value)
    const disChaPowerSingleGen = computed(() => powerSingleBlock.value * numOfCellsPerGen.value * etaDischarge.value)
    const chargePowerSingleGen_MW = computed(() => chargePowerSingleGen.value / 1000000)
    const disChaPowerSingleGen_MW = computed(() => disChaPowerSingleGen.value / 1000000)
    const chargePower = computed(() => powerBlocksSim.value / etaCharge.value)  // 电站总充电功率
    const disChaPower = computed(() => powerBlocksSim.value * etaCharge.value)  // 电站总放电功率

    const numRopePerBlock = ref(4)
    const numPulleyPerRope = ref(14)
    const safetyRatioRope = ref(5)  // 钢丝绳安全系数，取值5~9
    const ropeTripTimes = computed(() => 2 * numPulleyPerRope.value)

    const forceRope = computed(() => weightBlock.value / numRopePerBlock.value / ropeTripTimes.value)
    const forceRopeBreak = computed(() => forceRope.value * safetyRatioRope.value)
    const lvlRope = ref(1960);
    const ropeCoreClass = ref("独立钢绳芯")  // 独立钢绳芯  天然纤维芯
    const ropeCoreClasses = getRopeCoreClass()
    const ropeClass = ref("单层钢丝绳")
    const ropeClasses = getRopeClass()
    const ropeStrands = computed(() => getRopeStrands(ropeClass.value, ropeCoreClass.value))
    const ropeStrand = ref("6*36")
    const diameterRope_mm = computed(() => {
        return calRopeDiameter(forceRopeBreak.value, lvlRope.value, ropeClass.value, ropeCoreClass.value, ropeStrand.value)
    })


    const DiameterPulley = computed(() => {
        if (diameterRope_mm.value <= 6) {
            return 0.125 as number
        } else if (diameterRope_mm.value < 7) {
            return 0.140 as number
        } else if (diameterRope_mm.value < 8) {
            return 0.16 as number
        } else if (diameterRope_mm.value < 9) {
            return 0.18 as number
        } else if (diameterRope_mm.value < 10) {
            return 0.18 as number
        } else if (diameterRope_mm.value < 11) {
            return 0.26 as number
        } else if (diameterRope_mm.value < 13) {
            return 0.315 as number
        } else if (diameterRope_mm.value < 14) {
            return 0.355 as number
        } else if (diameterRope_mm.value < 16) {
            return 0.40 as number
        } else if (diameterRope_mm.value < 17) {
            return 0.45 as number
        } else if (diameterRope_mm.value < 18) {
            return 0.5 as number
        } else if (diameterRope_mm.value < 19) {
            return 0.5 as number
        } else if (diameterRope_mm.value < 20) {
            return 0.56 as number
        } else if (diameterRope_mm.value < 21) {
            return 0.56 as number
        } else if (diameterRope_mm.value < 22) {
            return 0.63 as number
        } else if (diameterRope_mm.value < 24) {
            return 0.63 as number
        } else if (diameterRope_mm.value < 25) {
            return 0.63 as number
        } else if (diameterRope_mm.value < 26) {
            return 0.71 as number
        } else if (diameterRope_mm.value < 28) {
            return 0.71 as number
        } else if (diameterRope_mm.value < 32) {
            return 0.80 as number
        } else if (diameterRope_mm.value < 36) {
            return 0.90 as number
        } else if (diameterRope_mm.value < 40) {
            return 1.120 as number
        } else if (diameterRope_mm.value < 44) {
            return 1.25 as number
        } else if (diameterRope_mm.value < 50) {
            return 1.40 as number
        } else if (diameterRope_mm.value < 56) {
            return 1.60 as number
        } else if (diameterRope_mm.value < 60) {
            return 1.8 as number
        } else {
            return 2 as number
        }
    })
    const widthSinglePulley = computed(() => {
        // 根据https://yunqi.qq.com/read/29976671/27计算滑轮宽度，未完全实现
        if (DiameterPulley.value <= 0.225) {
            return 0.06 as number
        } else if (DiameterPulley.value <= 0.25) {
            return 0.06 as number
        } else if (DiameterPulley.value <= 0.28) {
            return 0.064
        } else if (DiameterPulley.value <= 0.315) {
            return 0.064
        } else if (DiameterPulley.value <= 0.355) {
            return 0.068
        } else if (DiameterPulley.value <= 0.400) {
            return 0.072
        } else if (DiameterPulley.value <= 0.45) {
            if (diameterRope_mm.value <= 24) {
                return 0.08
            } else {
                return 0.114
            }
        } else if (DiameterPulley.value <= 0.5) {
            if (diameterRope_mm.value <= 20) {
                return 0.072
            } else {
                return 0.09
            }
        } else if (DiameterPulley.value <= 0.56) {
            return 0.08
        } else if (DiameterPulley.value <= 0.63) {
            return 0.09
        } else if (DiameterPulley.value <= 0.71) {
            return 0.09
        } else if (DiameterPulley.value <= 0.80) {
            return 0.128
        } else if (DiameterPulley.value <= 0.90) {
            return 0.128
        } else if (DiameterPulley.value <= 1) {
            return 0.128
        } else if (DiameterPulley.value <= 1.12) {
            return 0.14
        } else if (DiameterPulley.value <= 1.25) {
            return 0.154
        } else if (DiameterPulley.value <= 1.4) {
            return 0.154
        } else {
            return 0.168
        }
    })
    const bPulleyOuter = computed(() => {
        // 滑轮的绳槽口宽度，即b
        // 根据https://yunqi.qq.com/read/29976671/27计算滑轮宽度，未完全实现
        if (DiameterPulley.value <= 0.225) {
            return 0.037 as number
        } else if (DiameterPulley.value <= 0.25) {
            return 0.037 as number
        } else if (DiameterPulley.value <= 0.28) {
            return 0.037
        } else if (DiameterPulley.value <= 0.315) {
            return 0.037
        } else if (DiameterPulley.value <= 0.355) {
            return 0.05
        } else if (DiameterPulley.value <= 0.400) {
            return 0.043
        } else if (DiameterPulley.value <= 0.45) {
            if (diameterRope_mm.value <= 24) {
                return 0.050
            } else {
                return 0.073
            }
        } else if (DiameterPulley.value <= 0.5) {
            if (diameterRope_mm.value <= 20) {
                return 0.05
            } else {
                return 0.06
            }
        } else if (DiameterPulley.value <= 0.56) {
            return 0.06
        } else if (DiameterPulley.value <= 0.63) {
            return 0.06
        } else if (DiameterPulley.value <= 0.71) {
            return 0.062
        } else if (DiameterPulley.value <= 0.80) {
            return 0.075
        } else if (DiameterPulley.value <= 0.90) {
            return 0.077
        } else if (DiameterPulley.value <= 1) {
            return 0.092
        } else if (DiameterPulley.value <= 1.12) {
            return 0.092
        } else if (DiameterPulley.value <= 1.25) {
            return 0.105
        } else if (DiameterPulley.value <= 1.4) {
            return 0.105
        } else {
            return 0.105
        }
    })
    const widthPulleySideWall = computed(() => widthSinglePulley.value / 2)
    const widthForPulley = computed(() => (numPulleyPerRope.value * widthSinglePulley.value + 2 * widthPulleySideWall.value) * numRopePerBlock.value)
    const radiusPulleyGroove = computed(() => {
        let r = -1
        if (diameterRope_mm.value <= 6) {
            r = 3.3
        } else if (diameterRope_mm.value <= 7) {
            r = 3.8
        } else if (diameterRope_mm.value <= 8) {
            r = 4.3
        } else if (diameterRope_mm.value <= 9) {
            r = 5.0
        } else if (diameterRope_mm.value <= 10) {
            r = 5.5
        } else if (diameterRope_mm.value <= 11) {
            r = 6.0
        } else if (diameterRope_mm.value <= 12) {
            r = 6.5
        } else if (diameterRope_mm.value <= 13) {
            r = 7.0
        } else if (diameterRope_mm.value <= 14) {
            r = 7.5
        } else if (diameterRope_mm.value <= 15) {
            r = 8.2
        } else if (diameterRope_mm.value <= 16) {
            r = 9.0
        } else if (diameterRope_mm.value <= 17) {
            r = 9.5
        } else if (diameterRope_mm.value <= 18) {
            r = 10
        } else if (diameterRope_mm.value <= 19) {
            r = 10.5
        } else if (diameterRope_mm.value <= 20) {
            r = 11.0
        } else if (diameterRope_mm.value <= 21) {
            r = 11.5
        } else if (diameterRope_mm.value <= 22) {
            r = 12.0
        } else if (diameterRope_mm.value <= 23) {
            r = 12.5
        } else if (diameterRope_mm.value <= 24) {
            r = 13.0
        } else if (diameterRope_mm.value <= 25) {
            r = 13.5
        } else if (diameterRope_mm.value <= 26) {
            r = 14.0
        } else if (diameterRope_mm.value <= 28) {
            r = 15.0
        } else if (diameterRope_mm.value <= 30) {
            r = 16.0
        } else if (diameterRope_mm.value <= 32) {
            r = 17.0
        } else if (diameterRope_mm.value <= 34) {
            r = 18.0
        } else if (diameterRope_mm.value <= 36) {
            r = 19.0
        } else if (diameterRope_mm.value <= 38) {
            r = 20.0
        } else if (diameterRope_mm.value <= 40) {
            r = 21.0
        } else if (diameterRope_mm.value < 41) {
            r = 22.0
        } else if (diameterRope_mm.value < 43) {
            r = 23.0
        } else if (diameterRope_mm.value <= 45) {
            r = 24
        } else if (diameterRope_mm.value <= 47) {
            r = 25
        } else if (diameterRope_mm.value <= 48.5) {
            r = 26
        } else if (diameterRope_mm.value <= 50) {
            r = 27.0
        } else if (diameterRope_mm.value <= 52) {
            r = 28
        } else if (diameterRope_mm.value <= 54.5) {
            r = 29
        } else if (diameterRope_mm.value <= 56) {
            r = 30.0
        } else if (diameterRope_mm.value <= 58) {
            r = 31
        } else if (diameterRope_mm.value <= 60.5) {
            r = 32.0
        } else {
            console.log(`钢丝绳直径超范围，不能大于60.5mm，当前为${diameterRope_mm}mm`)
        }
        return r / 1000
    })
    const d1PulleySideWall = computed(() => DiameterPulley.value / 25 * 29)

    const massRopePer100 = computed(() => {
        return calRopeMassPer100m(forceRopeBreak.value, lvlRope.value, ropeClass.value, ropeCoreClass.value, ropeStrand.value)
    })

    // const lengthRopeGuidance = ref(160)
    const lengthRopeGuidance = computed(() => {
        return Math.ceil(lengthReel.value / 2 / Math.tan(1.5 / 180 * Math.PI)) * 2
    })
    const lengthRopeTrips = computed(() => ropeTripTimes.value * heightTower.value)
    const lengthRope = computed(() => lengthRopeGuidance.value + lengthRopeTrips.value)
    const velRope = computed(() => velWeight_m_s.value * ropeTripTimes.value)
    const diameterReel = ref(2.3)  // 卷筒直径
    const lengthReel = ref(1.1) // 卷筒卷线段长度
    const girthReel = computed(() => Math.PI * diameterReel.value) // 卷筒周长
    const speedHShaft = computed(() => speedRotateGen.value)
    const powerHShaft = computed(() => chargePowerSingleGen.value / 2)  // 单位W

    // 卷筒转速等于驱动线速度除以绕线一圈的周长
    const girthReelInner = computed(() => Math.PI * (diameterReel.value + diameterRope_mm.value / 1000)) // 卷筒上缠绕的最内层钢丝绳周长
    const speedLShaft = computed(() => velRope.value * 60 / girthReelInner.value)  // 卷筒和副轴转速
    const speedRotateReel = computed(() => speedLShaft.value)
    const powerLShaft = computed(() => chargePowerSingleGen.value / 2)  // 单个发电机功率除以2，单位W
    const dLShaft_mm = computed(() => calShaftDiameter(powerLShaft.value / 1000, speedLShaft.value))
    const speedRatio2 = computed(() => speedHShaft.value / speedLShaft.value)

    // torque = 9550P/N，因为是双出轴发电电动机，所以功率需要除以2
    const torqueHShaft = computed(() => powerHShaft.value * 9.549 / speedRotateGen.value)
    // 副轴高速段功率，不考虑变速箱效率
    const torqueLShaft = computed(() => powerLShaft.value * 9.549 / speedLShaft.value)

    const dHShaft_mm = computed(() => calShaftDiameter(chargePowerSingleGen.value / 2000, speedRotateGen.value))

    const massSingleRope = computed(() => lengthRope.value / 100 * massRopePer100.value) // kg
    const massRopes = computed(() => massSingleRope.value * numRopePerBlock.value * totalBlocksNum.value)
    const numRopeLaps = computed(() => lengthRopeTrips.value / girthReelInner.value)
    const numLapsPerLayer = computed(() => lengthReel.value / diameterRope_mm.value * 1000)
    const numRopeLayers = computed(() => numRopeLaps.value / numLapsPerLayer.value)
    const diameterReelSideWall = computed(() => Number((diameterReel.value + (diameterRope_mm.value / 1000 * numRopeLayers.value) * 1.2).toFixed(2))) // 不布置碟刹的挡边的高度
    const diameterReelSideBrake = computed(() => Number((diameterReelSideWall.value + 0.2).toFixed(2)))  // 碟刹所在的挡边直径
    const widthReelSideWall = computed(() => { // 挡边宽度
        if (diameterRope_mm.value <= 40) {
            return 0.04
        } else if (diameterRope_mm.value >= 100) {
            return 0.1
        } else {
            return diameterRope_mm.value * 0.001
        }
    })

    const lengthHShaft = computed(() => Number(widthGenRegion.value) / 4)
    const numHShaft = computed(() => numOfGens.value * 2)
    const massHShaft = computed(() => lengthHShaft.value * Math.PI * (dHShaft_mm.value / 2000) ** 2 * 7800)
    const massHShafts = computed(() => numHShaft.value * massHShaft.value)

    const lengthLShaft = computed(() => lengthBlock.value + 2 * Number(distancePillarWeight.value)) // 副轴低速段长度
    const numLShaft = computed(() => totalBlocksNum.value) // 副轴低速段数量
    const massLShaft = computed(() => lengthLShaft.value * Math.PI * (dLShaft_mm.value / 2000) ** 2 * 7800)
    // 副轴低速段总质量，L表示低速
    const massLShafts = computed(() => massLShaft.value * numLShaft.value)

    const lengthL0Shaft = computed(() => Number(widthGenRegion.value) / 2 - lengthHShaft.value)
    const massL0Shaft = computed(() => lengthL0Shaft.value * Math.PI * (dLShaft_mm.value / 2000) ** 2 * 7800)
    const numL0Shaft = computed(() => numOfGens.value * 2)
    const massL0Shafts = computed(() => numL0Shaft.value * massL0Shaft.value)
    // 所有主副轴的总质量
    const massShaftTotal = computed(() => massHShafts.value + massLShafts.value + massL0Shafts.value)

    const massTotalShaftAndRopes = computed(() => massShaftTotal.value + massRopes.value)
    const priceRope = ref(9000)
    const priceShaft = ref(20000)
    const priceRopes = computed(() => Number(priceRope.value) * massRopes.value / 1000)
    const priceShafts = computed(() => Number(priceShaft.value) * massShaftTotal.value / 1000)

    const timeC1 = ref(2)  // 储能时加速过程所需要的时间
    const accelerationC1 = computed(() => velWeight_m_s.value / timeC1.value)
    const distanceC1 = computed(() => 0.5 * velWeight_m_s.value * timeC1.value)
    const forceC1 = computed(() => massBlock.value * accelerationC1.value)
    const ratioC1 = computed(() => forceC1.value / weightBlock.value)
    const torqueLShaftMax = computed(() => torqueLShaft.value * (1 + ratioC1.value))
    const accelerationC2 = computed(() => -g.value);
    const timeC2 = computed(() => -velWeight_m_s.value / accelerationC2.value)
    const distanceC2 = computed(() => 0.5 * velWeight_m_s.value * timeC2.value)

    const gapBlockPulley = ref(0.2)
    const gapPulleys = computed(() => DiameterPulley.value * 1.2)
    const thickPulleyLayer = ref(0.5)
    const heightPulleyLayer = computed(() => 1.5 + 3 * DiameterPulley.value + gapPulleys.value)
    const thickGenLayer = ref(0.5)
    const heightGenLayer = computed(() => Math.ceil(diameterReel.value * 2.5 + 5))
    const thickRoof = ref(0.4)
    const lengthPadding = ref(5) // 重物长度方向屋顶平面的伸出长度
    const widthPadding = ref(5) // 重物宽度方向屋顶平面的伸出长度
    const gapReel = ref(0.5) // 两个卷筒之间的间隙

    const widthBearing = computed(() => {
        /**
         * 根据轴径计算轴承座宽度
         */
    })

    const calInfo = computed(() => {
        if (numRopePerBlock.value * lengthReel.value > lengthBlock.value + 2 * Number(distancePillarWeight.value)) {
            return {
                success: false,
                msg: `单个重物卷筒所需轴向总长度为${numRopePerBlock.value * lengthReel.value}，大于塔顶单个重物的长度方向总空间${lengthBlock.value + 2 * Number(distancePillarWeight.value)}，卷筒布置不下！`
            }
        } else if (diameterReel.value > widthBlock.value + 2 * Number(distancePillarWeight.value)) {
            return {
                success: false,
                msg: `卷筒直径为${diameterReel.value}，大于塔顶单个重物宽度方向总空间${widthBlock.value + 2 * Number(distancePillarWeight.value)}，卷筒布置不下！`
            }
        } else if (numGensSim.value > numOfGens.value) {
            return {
                success: false,
                msg: `同时运行的发电机数量(${numGensSim.value})不能超过总发电机数量(${numOfGens.value})!`
            }
        } else if (widthForPulley.value > lengthBlock.value) {
            return {
                success: false,
                msg: `滑轮组宽度(${widthForPulley.value}m)超过重物块长度(${lengthBlock.value}m)，这会导致滑轮组无法布置，请检查！`
            }
        } else {
            return {
                success: true,
                msg: "success"
            }
        }
    })

    const sgesStoreState = ref<string>()
    const rendering = ref<boolean>(false)

    return {
        sgesStoreState,
        rendering,
        diameter_pillar,
        diameterReelSideWall, lengthPadding, widthPadding, gapReel,
        widthReelSideWall,
        timeC2, accelerationC2, distanceC2,
        timeC1, distanceC1, forceC1, ratioC1, torqueLShaftMax, d1PulleySideWall,
        accelerationC1,
        calInfo,
        priceRope,
        priceShaft,
        priceRopes,
        priceShafts,
        massShaftTotal,
        massTotalShaftAndRopes,
        lengthL0Shaft,
        massL0Shaft,
        numRopeLaps,
        numLapsPerLayer,
        numRopeLayers,
        lengthLShaft,
        numLShaft,
        massLShaft,
        massRopes,
        massRopePer100,
        massSingleRope,
        speedRatio2,
        ropeTripTimes,
        lengthRopeGuidance,
        lengthRopeTrips,
        lengthRope,
        velRope,
        diameterReel,
        lengthReel,
        girthReel,
        ropeCoreClass,
        ropeCoreClasses,
        ropeClass,
        ropeClasses,
        ropeStrands,
        ropeStrand,
        lvlRope,
        forceRopeBreak,
        safetyRatioRope,
        diameterRope_mm,
        forceRope,
        numRopePerBlock,
        numPulleyPerRope,
        powerBlocksSim,
        chargePower,
        disChaPower,
        chargePowerSingleGen_MW,
        disChaPowerSingleGen_MW,
        chargePowerSingleGen,
        disChaPowerSingleGen,
        powerSingleBlock,
        powerSingleBlock_MW,
        speedRotateGen,
        velWeight_m_h,
        velWeight_m_s,
        proSim,
        timeSinglePass,
        areaCoe,
        areaTotalSta,
        areaTotalTower,
        widthPerGenGroup,
        lengthPerGenGroup,
        areaPerGenGroup,
        areaControlRoom,
        distancePillarWeight,
        totalMassAssistance_t,
        totalMassAssistance,
        totalWeightAssistance,
        pillar_set,
        etaCharge_100,
        etaDischarge_100,
        etaSystem_100,
        capChargeTotalSta,
        capDischargeTotalSta,
        powerChargeTotalSta,
        totalChargeTime,
        cal_power,
        vibrant_para,
        vibrant_option,
        heightTower,
        density,
        lengthBlock,
        widthBlock,
        heightBlock,
        etaSystem,
        volumeBlock,
        massBlock,
        etaCharge,
        etaDischarge,
        totalBlocksNum,
        totalMassBlocks,
        totalGravityEnergy,
        g,
        totalGravityEnergy_MJ,
        weightBlock,
        widthGenRegion,
        numOfGens,
        numOfCellsPerSide,
        numOfCellsPerGen,
        numGensSim,
        speedHShaft,
        torqueHShaft,
        dHShaft_mm,
        speedLShaft,
        powerLShaft,
        torqueLShaft,
        dLShaft_mm,
        lengthHShaft,
        massHShaft,
        numHShaft,
        massHShafts,
        massLShafts,
        numL0Shaft,
        massL0Shafts,
        powerHShaft,
        speedRotateReel,
        girthReelInner,
        widthForPulley, widthSinglePulley, bPulleyOuter,
        numGensPerGroup, diameterReelSideBrake, DiameterPulley, radiusPulleyGroove, widthPulleySideWall,
        gapBlockPulley, gapPulleys, thickPulleyLayer, heightPulleyLayer, thickGenLayer, heightGenLayer, thickRoof
    }
})

